package com.javachamp.exceptions;

public class TryFinally {

	public static void main(String[] args) {
		BusinessLogic logic = new BusinessLogic();
		SimpleDelegate delegate = new SimpleDelegate(logic);
		int length = delegate.lengthOfString("123456789");
		System.out.println(length);
	}
}

class SimpleDelegate {

	BusinessLogic logic;

	public SimpleDelegate(BusinessLogic logic) {
		this.logic = logic;
	}

	public int lengthOfString(String string) {
		long start = System.currentTimeMillis();
		try {
			return logic.lengthOfString(string);
		}
		finally {
			try {
				Thread.sleep(2000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			System.out.println("lengthOfString took " + (System.currentTimeMillis()-start));
		}
	}
}

class BusinessLogic {
	public int lengthOfString(String string) {
		return string.length();
	}
}
